home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk16 / humbird2.0 / humbird2.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  7KB  |  233 lines

  1. /*HUMBIRD v2.0 by C&P SOFTWARE************************************************
  2.  *                                             *
  3.  *        This code is copywright 1988 by C&P SOFTWARE and is          *
  4.  *    put in the public domain.  All or any part of this code is           *
  5.  *    freely distributable and can be used in other programs with the      *
  6.  *    agreement that this noticed must remain intact.                 *
  7.  *                                         *
  8.  *****************************************************************************
  9.  *                  DATA DECLARATIONS                     *
  10.  *****************************************************************************/
  11.  
  12. #include "exec/types.h"
  13. #include "intuition/intuition.h"
  14. #include "intuition/intuitionBase.h"
  15. #include "libraries/dos.h"
  16.  
  17. #define ADOS     "AmigaDOS"
  18. #define SYSPTS    i=0; i<POINTERSIZE; i++ 
  19. #define PREFSIZE  232L
  20.  
  21. char   *Copyright = "Copyright 1988 by C&P SOFTWARE";
  22. struct IntuitionBase *IntuitionBase,*OpenLibrary();
  23. struct GfxBase *GfxBase;
  24. struct Screen scren, *CusScrens;
  25. struct Window *Wdw;
  26. struct ViewPort *WVP,*ViewPortAddress();
  27. struct   Preferences    OurPrefs;
  28.  
  29. UWORD  PSprite_Data[4][44] = {
  30.     {  /* Humbird wings up */
  31.     0,0,
  32.     0x0000,0x0000,0x0000,0x0000,0x0001,0x0000,
  33.     0x0006,0x0000,0x1C0E,0x0004,0x363C,0x0010,0xF3F8,0x0C20,
  34.     0x17FB,0x1818,0x07FE,0x0400,0x03F8,0x0300,0x00F0,0x00F0,
  35.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  36.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFFB,0x00B0,
  37.     0x0E00,0x0777,
  38.     0,0
  39.     },
  40.     {  /* Humbird wings 1/4 */
  41.     0,0,
  42.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  43.     0x0000,0x0000,0x1C1F,0x0010,0x363C,0x0024,0xF3F0,0x0C90,
  44.     0x17F8,0x1870,0x07FF,0x0400,0x03F8,0x0200,0x00F0,0x0000,
  45.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  46.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFFB,0x00B0,
  47.     0x0E00,0x0777,
  48.     0,0,
  49.     },
  50.     {  /* Humbird wings 1/2 */
  51.     0,0,
  52.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  53.     0x0000,0x0000,0x1C00,0x0000,0x3600,0x0000,0xF3E0,0x0C00,
  54.     0x17F8,0x18C0,0x07FF,0x0460,0x03FC,0x0230,0x00FF,0x0008,
  55.     0x0003,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  56.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFFB,0x00B0,
  57.     0x0E00,0x0777,
  58.     0,0
  59.     },
  60.     {  /* Humbird wings down */
  61.     0,0,
  62.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  63.     0x0000,0x0000,0x1C00,0x0000,0x3600,0x0000,0xF3E0,0x0C00,
  64.     0x17FB,0x1980,0x07FE,0x0480,0x03F8,0x0260,0x00F8,0x0010,
  65.     0x000C,0x0008,0x0006,0x0004,0x0000,0x0000,0x0000,0x0000,
  66.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFFB,0x00B0,
  67.     0x0E00,0x0777,
  68.     0,0
  69.     },
  70. };
  71.  
  72. UWORD  Blank_Data[44] = {  /* Humbird gone */
  73.     0,0,
  74.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  75.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  76.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  77.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  78.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  79.     0x0000,0x0000,
  80.     0,0
  81.     };
  82.  
  83. USHORT PointerData[POINTERSIZE];
  84. int    i, ok = 0;
  85. short  mx,my;
  86. ULONG lv;
  87.  
  88. _main() /* No parameters, so why not save some space */
  89. {
  90. char *strcmp();
  91. char WTitle[9];
  92.  
  93.     SetTaskPri(FindTask(NULL),-2L); /* not to interfere with DOS */
  94.     strcpy(WTitle,ADOS);
  95.  
  96.     /********************** Standard Library set up **********************/
  97.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  98.     if(!IntuitionBase) cleanup();
  99.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  100.     if(!GfxBase) cleanup();
  101.  
  102.     /***************** Magic to get first screen pointer *****************/
  103.     ok = GetScreenData(&scren,sizeof(struct Screen),WBENCHSCREEN,NULL);
  104.     if (!ok) cleanup();
  105.  
  106.     /**** Get and save system prefs so we can restore them upon exit *****/
  107.     GetPrefs (&OurPrefs, PREFSIZE );
  108.     for(SYSPTS)
  109.         PointerData[i] = OurPrefs.PointerMatrix[i];
  110.  
  111.     /***** Loop thru all system windows to find the AmigaDOS window ******/
  112.     Wdw = scren.FirstWindow;
  113.     while (Wdw)
  114.         {
  115.         if (strcmp(Wdw->Title ,WTitle)  == 0)
  116.             break;
  117.         Wdw = Wdw->NextWindow;
  118.     }
  119.     if(!Wdw) cleanup(); /* No AmigaDOS window */
  120.  
  121.     /*********************** Set up the colors ***************************/
  122.     WVP = (struct ViewPort *)ViewPortAddress(Wdw);
  123.     SetColors();
  124.  
  125.     /********************** Get the  mouse x/y ***************************/
  126.     mx = Wdw -> MouseX;
  127.     my = Wdw -> MouseY;
  128.  
  129.     /******************** Initial humbird display ************************/
  130.     lv = LockIBase(0L);
  131.     SetPointer(IntuitionBase->ActiveWindow,&PSprite_Data[0],18,16,0,-6);
  132.     UnlockIBase(lv);
  133.     setp();
  134. }
  135.  
  136. setp()
  137. {
  138. int x, mm = 0;
  139. short tmx, tmy, off;
  140. ULONG Seconds, Micros, OldSecs, OldMics;
  141.  
  142.     do{    /* CurrentTime bug ??? */
  143.         CurrentTime(&OldSecs,&OldMics); /* Get initial time */
  144.     }while(OldSecs<=0 || OldMics<=0);
  145.     while(1){  /* FOREVER */
  146.         for(x=0;x<=3;){
  147.             tmx = Wdw -> MouseX;
  148.             tmy = Wdw -> MouseY;
  149.             if((tmx != mx) || (tmy != my)){ /* Mouse moved... */
  150.                 x = x + 1;
  151.                 mx = tmx; my = tmy;
  152.                 mm = 1; off = 0;  /* set move & mouseoff */
  153.                 do{  /* reset time */
  154.                     CurrentTime(&OldSecs,&OldMics);
  155.                 }while(OldSecs<=0 || OldMics<=0);
  156.             }
  157.             else{ /* No mouse movement */
  158.                 do{ /* Get time to compare with old time */
  159.                     CurrentTime(&Seconds,&Micros);
  160.                 }while(Seconds<=0 || Micros<=0);
  161.                 if(((Seconds - 10) > OldSecs) && (!off)){
  162.                     lv = LockIBase(0L); /* time > 10 secs and mouse is on */
  163.                     SetPointer(IntuitionBase->ActiveWindow,&Blank_Data,18,16,0,-6);
  164.                     UnlockIBase(lv);
  165.                     SetColors();
  166.                     off = 1; /* mouse is off */
  167.                 }    
  168.             }
  169.             if((x >= 0) && (x <= 3) && (mm)){ /* mouse moved = change pointer. */
  170.                 lv = LockIBase(0L);
  171.                 SetPointer(IntuitionBase->ActiveWindow,&PSprite_Data[x],18,16,0,-6);
  172.                 UnlockIBase(lv);
  173.                 mm = 0;
  174.             }
  175.             Chk_Abort(); /* Was the program aborted? */
  176.         }
  177.  
  178.     }
  179. }
  180.  
  181. cleanup()
  182. {
  183.  
  184.     /************* Close all our stuff and reset the pointer *************/
  185.     ok = 0;
  186.     ok = GetScreenData(&scren,sizeof(struct Screen),WBENCHSCREEN,NULL);
  187.     if (ok){
  188.         Wdw = scren.FirstWindow;
  189.         while (Wdw)
  190.             {
  191.             ClearPointer(Wdw);
  192.             Wdw = Wdw->NextWindow;
  193.         }
  194.         CusScrens = scren.NextScreen;
  195.         while(CusScrens){
  196.             Wdw = CusScrens->FirstWindow;
  197.             while (Wdw)
  198.                 {
  199.                 ClearPointer(Wdw);
  200.                 Wdw = Wdw->NextWindow;
  201.             }
  202.             CusScrens = CusScrens->NextScreen;
  203.         }
  204.     }
  205.     if(IntuitionBase) CloseLibrary(IntuitionBase);
  206.     if(GfxBase) CloseLibrary(GfxBase);
  207.     exit(0);
  208. }
  209.  
  210. Chk_Abort()
  211. {
  212.     if (SetSignal(0L, (ULONG) (SIGBREAKF_CTRL_C)) &
  213.         (SIGBREAKF_CTRL_C)) {
  214.         resetptr(PointerData);
  215.         cleanup();
  216.     }
  217. }
  218.  
  219. resetptr(data) /* reset system colors */
  220. USHORT data[];
  221. {
  222.    for(SYSPTS)
  223.     OurPrefs.PointerMatrix[i] = (data) ? data[i] : NULL;
  224.    SetPrefs(&OurPrefs,PREFSIZE);
  225. }
  226.    
  227. SetColors()
  228. {
  229.     SetRGB4(WVP,17,0,8,2);
  230.     SetRGB4(WVP,18,11,0,0);
  231.     SetRGB4(WVP,19,9,11,0);
  232. }
  233.